/*
**************************************************************************************
*Myriad Engine                                                                       *
*Copyright (C) 2006-2007, 5d Studios (www.5d-Studios.com)                            *
*                                                                                    *
*This library is free software; you can redistribute it and/or                       *
*modify it under the terms of the GNU Lesser General Public                          *
*License as published by the Free Software Foundation; either                        *
*version 2.1 of the License, or (at your option) any later version.                  *
*                                                                                    *
*This library is distributed in the hope that it will be useful,                     *
*but WITHOUT ANY WARRANTY; without even the implied warranty of                      *
*MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU                   *
*Lesser General Public License for more details.                                     *
*                                                                                    *
*You should have received a copy of the GNU Lesser General Public                    *
*License along with this library; if not, write to the Free Software                 *
*Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA      *
**************************************************************************************
*/
package leola.ast;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Abstract Syntax tree node
 * 
 * @author Tony
 *
 */
public abstract class ASTNode {

	/**
	 * Attributes
	 */
	private Map<String, Object>  attributes;
	
	/**
	 * Children
	 */
	private List<ASTNode> children;

	/**
	 */
	protected ASTNode() {
		this.attributes = new HashMap<String, Object>();
		this.children = new ArrayList<ASTNode>();
	}
	
	/**
	 * @return the attributes
	 */
	public Map<String, Object> getAttributes() {
		return attributes;
	}

	/**
	 * @param attributes the attributes to set
	 */
	public void setAttributes(Map<String, Object> attributes) {
		this.attributes = attributes;
	}
	
	/**
	 * Adds an attribute
	 * 
	 * @param key
	 * @param value
	 */
	public void setAttribute(String key, Object value) {
		this.attributes.put(key, value);
	}
	
	/**
	 * Gets an attribute
	 * 
	 * @param key
	 * @return
	 */
	public Object getAttribute(String key) {
		return this.attributes.get(key);
	}
	

	/**
	 * @return the children
	 */
	public List<ASTNode> getChildren() {
		return children;
	}
	
	/**
	 * @param node
	 */
	public void addChild(ASTNode node) {
		this.children.add(node);
	}

	/**
	 * @param children the children to set
	 */
	public void setChildren(List<ASTNode> children) {
		this.children = children;
	}
		
	/**
	 * Visits the {@link ASTNode}.
	 * 
	 * @param v
	 */
	public abstract void visit(ASTNodeVisitor v) throws Exception;
}
